import os
import gzip

src_data_path = "sdk-logs/download/"

dirname_list = [src_data_path+src_dirname+'/'  for src_dirname in os.listdir(src_data_path)]

# logfile_list = [dirname_list+logfiles for logfiles in dirname_list]

for dirname in dirname_list:
    for logfile in os.listdir(dirname):
        if logfile.endswith('.gz'):
            fin = gzip.open(dirname+logfile, 'rb')
            fout_name = logfile[:-3]
            if not fout_name.endswith('.log'):
                fout_name = fout_name+'.log'
            fout_path = str(dirname+fout_name)
            print(fout_path)
            fout = open(fout_path, 'wb')
            while True:
                buf = fin.read()
                if len(buf) < 1:
                    break
                fout.write(buf)
            fin.close()
            fout.close()
            os.remove(dirname+logfile)






